package com.luyuan.crm.sale.web.provider;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import org.springframework.stereotype.Component;

import com.luyuan.crm.member.model.MemberIntegral;
import com.luyuan.crm.sale.model.Order;
import com.ruijie.web.jsf.context.WizardScope;
import com.ruijie.web.jsf.provider.SelectItemsProvider;

@Component("integralDeductionProvider")
public class IntegralDeductionProvider implements SelectItemsProvider {

    @Override
    public List<SelectItem> getSelectItems(Object... arg0) {
        Order order = (Order) WizardScope.get("order");
        MemberIntegral memberIntegral = (MemberIntegral) WizardScope.get("memberIntegral");
        int currentIntegral = memberIntegral.getCurrentIntegral();
        double amount = order.getOldAmount();

        List<SelectItem> selectItems = new ArrayList<SelectItem>();
        selectItems.add(new SelectItem(0, ""));
        for (int i = 500, j = 0; i < currentIntegral & j < amount / 500; i += 500, j++) {
            selectItems.add(new SelectItem(i, i + ""));
        }
        return selectItems;
    }
}
